﻿using System;
using System.Linq;
using Lbb.Data;
using Lbb.User.DL;

namespace Lbb.User.DAL
{
    public class UserRepository : RepositoryBase<AspNetUsers>
    {
        public UserRepository(UserDataContext db)
            : base(db)
        {
        }

        #region NotSupported
        public override void Add(AspNetUsers obj)
        {
            throw new NotSupportedException();
        }

        public override void Delete(AspNetUsers obj)
        {
            throw new NotSupportedException();
        }

        public override void Update(AspNetUsers obj)
        {
            throw new NotSupportedException();
        }
        #endregion NotSupported

        #region Get
        public AspNetUsers Get(Guid? id)
        {
            return id.HasValue ? Get(d => d.UserId == id.Value) : null;
        }
        public AspNetUsers Get(string name)
        {
            if (string.IsNullOrEmpty(name)) return null;
            name = name.ToLower();
            return Get(d => d.LoweredUserName == name);
        }
        #endregion Get

        public int SetPassword(string applicationName, string userName, string newPassword, string passwordSalt, DateTime currentTimeUtc, int passwordFormat)
        {
            return ((UserDataContext)DB).SetPassword(applicationName, userName, newPassword, passwordSalt, currentTimeUtc, passwordFormat);
        }

        public int ResetPassword(string applicationName, string userName, string newPassword, int maxInvalidPasswordAttempts, int passwordAttemptWindow, string passwordSalt, DateTime currentTimeUtc, int passwordFormat, string passwordAnswer)
        {
            return ((UserDataContext)DB).ResetPassword(applicationName, userName, newPassword, maxInvalidPasswordAttempts, passwordAttemptWindow, passwordSalt, currentTimeUtc, passwordFormat, passwordAnswer);
        }
    }
}
